package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> queryPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
       Page pageResult=nursingProjectMapper.queryPage(name,status);
        return  PageResponse.of(pageResult, NursingProjectVo.class);
    }

    @Override
    public void addNursing(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject=new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto,nursingProject);
        nursingProject.setCreateBy(1L);
        nursingProject.setUpdateBy(1L);
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProject.setCreateTime(LocalDateTime.now());
//        nursingProject.setCreator();
        nursingProjectMapper.addNursing(nursingProject);
    }

    @Override
    public void deleteNursing(Integer id) {
        nursingProjectMapper.deleteNursing(id);
    }

    @Override
    public NursingProjectVo getById(Integer id) {
        return nursingProjectMapper.getById(id);
    }

    @Override
    public void updateNursing(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject=new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto,nursingProject);
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProject.setUpdateBy(1L);
        nursingProjectMapper.updateNursing(nursingProject);
    }

    @Override
    public List<NursingProjectVo> getAll() {

        return  nursingProjectMapper.getAll();
    }
}
